<style scoped>
    .item{
        height: 3.5rem;
        align-items: center
    }
</style>

<template>
    <ui-main>
        <van-search v-model="searchVal" placeholder="请输入搜索关键词" @cancel="onCancel" @clear="onClear"  @search="onSearch" />
        <van-cell class="item" @click.native="goDetail(item)" is-link :title="item.business_name" v-for="(item,index) in business" :key="index">
        </van-cell>
    </ui-main>
</template>

<script>
    import yw from '../mixins/ljy';

    export default {
        mixins: [yw],
        data() {
            return {
               business:[],tempList:[],
               searchVal:'',
               searchShow:true,
                isShow: false,
                vo:{},
                org_no:'',
                imgurl:''
            };
        },
        mounted() {
            this.$title('业务状态列表');
            this.$$getAllBusinessStatus().then(data => {
                if (this.$isArray(data.content)) {
                    this.business = data.content
                    this.tempList = data.content
                }
            }).catch(e => {
                console.error(e);
            });
            
        },
        methods: {
            onClear(){                
                this.searchVal = ''
                this.business = this.tempList
            },
            onCancel(){
                this.searchVal = ''
            },
            onSearch(v) {
                if(this.$isBlank(v)) {
                    this.business = this.tempList;
                    return;
                }
                var showData = []
                this.tempList.forEach(element => {
                    if ((element.business_name && element.business_name.indexOf(v) > -1)) {
                        showData.push(element)
                    }
                });
                this.business = showData
            },
            goDetail(item) {
                this.$router.push({
                    path: '/ztcx',
                    query: {
                        org_id:item.org_id,business_name:item.business_name
                    }
                })
            }
        },
        watch:{
            searchVal(){
                var showData = []
                this.tempList.forEach(element => {
                    if ((element.business_name && element.business_name.indexOf(this.searchVal) > -1)) {
                        showData.push(element)
                    }
                });
                this.business = showData
            }
        }
    }
</script>
